* @ingroup Language
*/
class Language {
+ /**
+ * Return autonyms in fetchLanguageName(s).
+ * @since 1.32
+ */
+ const AS_AUTONYMS = null;
+
+ /**
+ * Return all known languages in fetchLanguageName(s).
+ * @since 1.32
+ */
+ const ALL = 'all';
+
+ /**
+ * Return in fetchLanguageName(s) only the languages for which we have at
+ * least some localisation.
+ * @since 1.32
+ */
+ const SUPPORTED = 'mwfile';
+
/**
* @var LanguageConverter
*/
/**
* Get an array of language names, indexed by code.
* @param null|string $inLanguage Code of language in which to return the names
- * Use null for autonyms (native names)
+ * Use self::AS_AUTONYMS for autonyms (native names)
* @param string $include One of:
- * 'all' all available languages
+ * self::ALL all available languages
* 'mw' only if the language is defined in MediaWiki or wgExtraLanguageNames (default)
- * 'mwfile' only if the language is in 'mw' *and* has a message file
+ * self::SUPPORTED only if the language is in 'mw' *and* has a message file
* @return array Language code => language name (sorted by key)
* @since 1.20
*/
- public static function fetchLanguageNames( $inLanguage = null, $include = 'mw' ) {
- $cacheKey = $inLanguage === null ? 'null' : $inLanguage;
+ public static function fetchLanguageNames( $inLanguage = self::AS_AUTONYMS, $include = 'mw' ) {
+ $cacheKey = $inLanguage === self::AS_AUTONYMS ? 'null' : $inLanguage;
$cacheKey .= ":$include";
if ( self::$languageNameCache === null ) {
self::$languageNameCache = new HashBagOStuff( [ 'maxKeys' => 20 ] );
/**
* Uncached helper for fetchLanguageNames
* @param null|string $inLanguage Code of language in which to return the names
- * Use null for autonyms (native names)
+ * Use self::AS_AUTONYMS for autonyms (native names)
* @param string $include One of:
- * 'all' all available languages
+ * self::ALL all available languages
* 'mw' only if the language is defined in MediaWiki or wgExtraLanguageNames (default)
- * 'mwfile' only if the language is in 'mw' *and* has a message file
+ * self::SUPPORTED only if the language is in 'mw' *and* has a message file
* @return array Language code => language name (sorted by key)
*/
- private static function fetchLanguageNamesUncached( $inLanguage = null, $include = 'mw' ) {
+ private static function fetchLanguageNamesUncached(
+ $inLanguage = self::AS_AUTONYMS,
+ $include = 'mw'
+ ) {
global $wgExtraLanguageNames, $wgUsePigLatinVariant;
// If passed an invalid language code to use, fallback to en
- if ( $inLanguage !== null && !self::isValidCode( $inLanguage ) ) {
+ if ( $inLanguage !== self::AS_AUTONYMS && !self::isValidCode( $inLanguage ) ) {
$inLanguage = 'en';
}
}
}
- if ( $include === 'all' ) {
+ if ( $include === self::ALL ) {
ksort( $names );
return $names;
}
$returnMw[$coreCode] = $names[$coreCode];
}
- if ( $include === 'mwfile' ) {
+ if ( $include === self::SUPPORTED ) {
$namesMwFile = [];
# We do this using a foreach over the codes instead of a directory
# loop so that messages files in extensions will work correctly.
/**
* @param string $code The code of the language for which to get the name
- * @param null|string $inLanguage Code of language in which to return the name (null for autonyms)
- * @param string $include 'all', 'mw' or 'mwfile'; see fetchLanguageNames()
+ * @param null|string $inLanguage Code of language in which to return the name
+ * (SELF::AS_AUTONYMS for autonyms)
+ * @param string $include See fetchLanguageNames()
* @return string Language name or empty
* @since 1.20
*/
- public static function fetchLanguageName( $code, $inLanguage = null, $include = 'all' ) {
+ public static function fetchLanguageName(
+ $code,
+ $inLanguage = self::AS_AUTONYMS,
+ $include = self::ALL
+ ) {
$code = strtolower( $code );
$array = self::fetchLanguageNames( $inLanguage, $include );
return !array_key_exists( $code, $array ) ? '' : $array[$code];
* @deprecated No-op since 1.28
*/
function initEncoding() {
+ wfDeprecated( __METHOD__, '1.28' );
// No-op.
}
* @deprecated No-op since 1.28
*/
function recodeForEdit( $s ) {
+ wfDeprecated( __METHOD__, '1.28' );
return $s;
}
* @deprecated No-op since 1.28
*/
function recodeInput( $s ) {
+ wfDeprecated( __METHOD__, '1.28' );
return $s;
}
return;
}
$this->mMagicHookDone = true;
- Hooks::run( 'LanguageGetMagic', [ &$this->mMagicExtensions, $this->getCode() ] );
+ Hooks::run( 'LanguageGetMagic', [ &$this->mMagicExtensions, $this->getCode() ], '1.16' );
}
/**
$this->mExtendedSpecialPageAliases =
self::$dataCache->getItem( $this->mCode, 'specialPageAliases' );
Hooks::run( 'LanguageGetSpecialPageAliases',
- [ &$this->mExtendedSpecialPageAliases, $this->getCode() ] );
+ [ &$this->mExtendedSpecialPageAliases, $this->getCode() ], '1.16' );
}
return $this->mExtendedSpecialPageAliases;
* @return string
*/
private function truncateInternal(
- $string, $length, $ellipsis = '...', $adjustLength = true, $measureLength, $getSubstring
+ $string, $length, $ellipsis, $adjustLength, $measureLength, $getSubstring
) {
if ( !is_callable( $measureLength ) || !is_callable( $getSubstring ) ) {
throw new InvalidArgumentException( 'Invalid callback provided' );
* the "raw" tag (-{R| }-) to prevent conversion.
*
* This function is called "markNoConversion" for historical
- * reasons.
+ * reasons *BUT DIFFERS SIGNIFICANTLY* from
+ * LanguageConverter::markNoConversion(), with which it is easily
+ * confused.
*
* @param string $text Text to be used for external link
* @param bool $noParse Wrap it without confirming it's a real URL first
* @return string The tagged text
+ * @deprecated since 1.32, use LanguageConverter::markNoConversion()
+ * instead.
*/
public function markNoConversion( $text, $noParse = false ) {
+ wfDeprecated( __METHOD__, '1.32' );
// Excluding protocal-relative URLs may avoid many false positives.
if ( $noParse || preg_match( '/^(?:' . wfUrlProtocolsWithoutProtRel() . ')/', $text ) ) {
return $this->mConverter->markNoConversion( $text );
* @throws MWException
* @return string $prefix . $mangledCode . $suffix
*/
- public static function getFileName( $prefix = 'Language', $code, $suffix = '.php' ) {
+ public static function getFileName( $prefix, $code, $suffix = '.php' ) {
if ( !self::isValidBuiltInCode( $code ) ) {
throw new MWException( "Invalid language code \"$code\"" );
}